import asyncio
import contextvars

# declare context var
import random


ctx = contextvars.ContextVar('context')

async def task1():
    ctx.set('1')
    print('task1->', ctx.get())


async def task2():
    ctx.set('2')
    print('task2->', ctx.get())


async def main():
    await asyncio.gather(task1(), task2())
    print(ctx.get())



if __name__ == '__main__':
    asyncio.run(main())